﻿/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2012-2018. All rights reserved.
 * Description:
 * Author: 辛爱国 x30005137
 * Create: 2020-07-28
 * Notes: 无
 */
#include <QMouseEvent>
#include <QString>
#include <QPixmap>
#include <QPicture>
#include <QPainter>
#include <QDebug>
#include <QAction>
#include <QVariant>
#include <QGraphicsDropShadowEffect>
#include <QDesktopServices>
#include <QFontMetrics>
#include <QTextOption>
#include <QTextCodec>
#include <qfont.h>
#include <qmessagebox.h>
#if defined(Q_OS_WIN)
#include <UIAutomation.h>
#endif

#include <qapplication.h>
#include <QDesktopWidget>
#include <qscreen.h>
#include <QMessageBox>
#include "errorevent.h"
#include "volumeupdateevent.h"
#include "sharedisplayevent.h"
#include "connectresultevent.h"
#include "sharestopevent.h"
#include "disconnectresultevent.h"
#include "serverstopshareevent.h"
#include "serverdisconnectevent.h"
#include "exitconffirmdialog.h"
#include "reconfirmation.h"
#include "mainwindow.h"


#pragma comment(lib, "user32.lib")
#pragma comment(lib, "Ole32.lib")
#pragma comment(lib, "oleaut32.lib")
#define TUP_LOG_PATH "log\\"


MainWindow::MainWindow(QWidget *parent) : HWDialog(parent)
{
    setupUi(this);

//#if defined(IDEASHAREKEY)
//    m_systray = new TrayIcon(tr("IdeaShare Key"), this, 5);              // 5行按钮v
//#else
//    m_systray = new TrayIcon(tr("IdeaShare"), this);
//#endif
    m_systray = new TrayIcon(tr("IdeaShare"),this);
    connect(m_systray, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this,
            SLOT(systray_activated(QSystemTrayIcon::ActivationReason)));
    m_systray->show();
    // 6/8位显示，无限制隐藏
    SetToScreenCodeMode(true);
    /* 设置无边框以及隐藏 */
    this->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowSystemMenuHint | Qt::WindowMinimizeButtonHint);
    /* 设置状态栏上显示图标 */
    this->setWindowIcon(QIcon(":image/images/100.ico"));

    this->setAttribute(Qt::WA_TranslucentBackground);

    connect(this, SIGNAL(messageNotify(uint32_t, bool, uint32_t)), SLOT(messageHandler(uint32_t, bool, uint32_t)));

    /* 初始化声音投放选择框 */
//    this->checkBoxMusic->setChecked(ideasharesdk::config::clientplay.value());
    this->labelResultInfo->setFocusPolicy(Qt::NoFocus);
    this->labelResultInfo->setWordWrap(true);
    this->labelResultInfo->setAlignment(Qt::AlignTop | Qt::AlignHCenter);

    this->labelTipEnterEnglish->setFocusPolicy(Qt::NoFocus);
    this->labelTipEnterEnglish->setWordWrap(true);
    this->labelTipEnterEnglish->setAlignment(Qt::AlignTop | Qt::AlignHCenter);

    // 窗口加阴影
    QGraphicsDropShadowEffect *shadow_effect = new QGraphicsDropShadowEffect(this);
    QColor color(0, 0, 0, 20); // 0, 0, 0, 20颜色值
    shadow_effect->setOffset(0, 0); // 0, 0设置的参数
    shadow_effect->setColor(color);
    shadow_effect->setBlurRadius(30); // 设置阴影半径30
    this->widgetWindow->setGraphicsEffect(shadow_effect);
    QGraphicsDropShadowEffect *shadow_ShareBod = new QGraphicsDropShadowEffect(this);
    shadow_ShareBod->setOffset(0, 0);
    shadow_ShareBod->setColor(color);
    shadow_ShareBod->setBlurRadius(30); // 设置阴影半径30
    this->widgetShareBody->setGraphicsEffect(shadow_ShareBod);
    this->horizontalSliderVolume->installEventFilter(this);
    this->frameErrorInfo->setVisible(false);
    init();
}
void  MainWindow::on_horizontalSliderVolume_sliderPressed()
{
    double scalrate = getCurrentRate(this);
    double rate = scalrate * 1.1;  // 1.1 图标放大系数
    if (this->horizontalSliderVolume->orientation() == Qt::Horizontal) {
        QRect rector = horizontalSliderVolume->property("ALLRECTWIN").toRect();
        int rectHeight = rector.height();
        int leftrightGroove = (rectHeight / 2.0 - 1) * rate;  // 2.0去一半 1个单位
        int widgrove = 2.0 * scalrate;   // 滑条宽2.0
        int mover = rectHeight / 2.0 * rate; // 2.0 取中值
        int handleHeight = rate * rectHeight + widgrove;
        QRect rect = horizontalSliderVolume->geometry();
        rect.setX(rector.x() * scalrate - leftrightGroove);  // 1.0 基础倍率
        rect.setY(rector.y() * scalrate);
        // 窗口长宽
        int width = rector.width() * scalrate + leftrightGroove * 2.0;  // 1.0 基础倍率 2.0 两边同时加
        this->horizontalSliderVolume->setRange(0, width);
        rect.setWidth((width < 1) ? 1 : width);
        rect.setHeight((rector.height() * scalrate < 1) ? 1 : (rector.height() * scalrate));
        horizontalSliderVolume->setGeometry(rect);
        horizontalSliderVolume->setStyleSheet(QString("QSlider::groove:horizontal{ height: %1px; left: %2px; right: %3px; }").arg(widgrove).
                                              arg(leftrightGroove).arg(leftrightGroove) +
                                              QString("QSlider::handle:horizontal{ width: %1px; margin: -%3px -%4px -%5px -%6px; }").arg(handleHeight).
                                              arg(mover).arg(mover).arg(mover).arg(mover)); // 10 biankuang
    }
}
void  MainWindow::on_horizontalSliderVolume_sliderMoved()
{
    on_horizontalSliderVolume_sliderPressed();
}
void  MainWindow::on_horizontalSliderVolume_sliderReleased()
{
    double rate = getCurrentRate(this);
    if (this->horizontalSliderVolume->orientation() == Qt::Horizontal) {
        QRect rector = horizontalSliderVolume->property("ALLRECTWIN").toRect();
        int rectHeight = rector.height();
        int leftrightGroove = (rectHeight / 2.0 - 1) * rate;  // 2.0去一半 1个单位
        int widgrove = 2.0 * rate;   // 滑条宽2.0
        int mover = rectHeight / 2.0 * rate; // 2.0 取中值
        int handleHeight = rate * rectHeight + widgrove;
        QRect rect = horizontalSliderVolume->geometry();
        rect.setX(rector.x() * rate - leftrightGroove);  // 1.0 基础倍率
        rect.setY(rector.y() * rate);
        // 窗口长宽
        int width = rector.width() * rate + leftrightGroove * 2.0;  // 1.0 基础倍率 2.0 两边同时加
        this->horizontalSliderVolume->setRange(0, width);
        rect.setWidth((width < 1) ? 1 : width);
        rect.setHeight((rector.height() * rate < 1) ? 1 : (rector.height() * rate));
        horizontalSliderVolume->setGeometry(rect);
        horizontalSliderVolume->setStyleSheet(QString("QSlider::groove:horizontal{ height: %1px; left: %2px; right: %3px; }").arg(widgrove).
                                              arg(leftrightGroove).arg(leftrightGroove) +
                                              QString("QSlider::handle:horizontal{ width: %1px; margin: -%3px -%4px -%5px -%6px; }").arg(handleHeight).
                                              arg(mover).arg(mover).arg(mover).arg(mover)); // 10 biankuang
    }
}
void MainWindow::InitUI()
{
//    m_PassCodeMode = ideasharesdk::config::closebutton == 0 ? true : false;
    SetToScreenCodeMode(m_PassCodeMode);
    IsShowChooseKeyBtn(m_PassCodeMode);
}
void  MainWindow::SetToScreenCodeMode(bool mode)
{
    if (!mode) {
        this->widgetPasswordShow->hide();
        this->widgetPasswordShow->setEnabled(false);
        this->unLimitpassCodewidget->show();
        this->unLimitpassCodewidget->setEnabled(true);
        this->unLimitpassCodewidget->SetFousOn(0); // 光标在0
    } else {
        this->widgetPasswordShow->show();
        this->widgetPasswordShow->setEnabled(true);
        this->unLimitpassCodewidget->hide();
        this->unLimitpassCodewidget->setEnabled(false);
    }
}
void MainWindow::on_pushButtonMin_clicked()
{
    showMinimized();
}
void MainWindow::ErrorDispear()
{
    qDebug() << "error disappear";
    on_pushButtonClear_clicked();
    this->frameErrorInfo->setVisible(false);
    this->m_errorTimer->stop();
     qDebug() << "error end";
}
void MainWindow::updateWait()
{
    QMatrix matrix;
    QPixmap image_wait(":/image/images/31.png");
    image_wait.scaled(this->labelWaitSign->size(), Qt::KeepAspectRatio);
    matrix.rotate(90 * this->m_spinIndex); // 每次旋转90
    this->labelWaitSign->setScaledContents(true);
    this->labelWaitSign->setPixmap(image_wait.transformed(matrix, Qt::FastTransformation));
    this->m_spinIndex > 2 ? this->m_spinIndex = 0 : this->m_spinIndex++;     // 0 1 2 3 转一圈
}

void MainWindow::processSendTimeout()
{
    this->m_isSendingRequest = false;
    this->pushButtonShare->setEnabled(true);
    this->pushButtonStop->setEnabled(true);
}

MainWindow::~MainWindow()
{
    qDebug() << "MainWindow deconstruction......";
//#if defined(IDEASHAREKEY)
//    ideasharesdk::terminal::notifyDisConnected();
//#endif
#if defined(Q_QS_WIN32)
    SetThreadExecutionState(ES_CONTINUOUS);
#endif
    if (m_waitTimer) {
        delete m_waitTimer;
        m_waitTimer = nullptr;
    }
    if (m_errorTimer) {
        delete m_errorTimer;
        m_errorTimer = nullptr;
    }
    if (m_aboutdialog) {
        delete m_aboutdialog;
        m_aboutdialog = nullptr;
    }
    if (m_collectlogdialog) {
        delete m_collectlogdialog;
        m_collectlogdialog = nullptr;
    }
    if (m_settingdialog) {
        delete m_settingdialog;
        m_settingdialog = nullptr;
    }
    if (m_settingMenudialog) {
        delete m_settingMenudialog;
        m_settingMenudialog = nullptr;
    }
    if (m_systray) {
        delete m_systray;
        m_systray = nullptr;
    }
    if (m_sendTimer) {
        delete m_sendTimer;
        m_sendTimer = nullptr;
    }
}

void MainWindow::handleConnectTimeout()
{
    //emit messageNotify(ideasharesdk::IDEASHARE_MSG_CONNECT_RET, false, IDEASHARE_ERROR_CONNECT_FAIL);
}

void MainWindow::init()
{
    this->m_waitTimer = new QTimer(this);
    this->m_waitTimer->setInterval(200); // 设置定时器200
    connect(this->m_waitTimer, SIGNAL(timeout()), this, SLOT(updateWait()));

    this->m_sendTimer = new QTimer(this);
    this->m_sendTimer->setSingleShot(true);
    this->m_sendTimer->setInterval(2000); // 设置定时器2000
    connect(this->m_sendTimer, SIGNAL(timeout()), this, SLOT(processSendTimeout()));

#if !defined(IDEASHAREKEY)
    this->m_connectTimeoutTimer = new QTimer(this);
    this->m_connectTimeoutTimer->setInterval(20 * 1000); // 设值定时器20*1000
    this->m_connectTimeoutTimer->setSingleShot(true);
    connect(this->m_connectTimeoutTimer, SIGNAL(timeout()), this, SLOT(handleConnectTimeout()));
#endif
    this->m_errorTimer = new QTimer(this);
    this->m_errorTimer->setInterval(3000);    // 定时器设置5000
    connect(this->m_errorTimer, SIGNAL(timeout()), this, SLOT(ErrorDispear()));

    // 将Label显示放在数组里
    keyLabels [0] = this->labelNumShow1; // 第1个字符显示
    keyLabels [1] = this->labelNumShow2; // 第2个字符显示
    keyLabels [2] = this->labelNumShow3; // 第3个字符显示
    keyLabels [3] = this->labelNumShow4; // 第4个字符显示
    keyLabels [4] = this->labelNumShow5; // 第5个字符显示
    keyLabels [5] = this->labelNumShow6; // 第6个字符显示
    keyLabels [6] = this->labelNumShow7; // 第7个字符显示
    keyLabels [7] = this->labelNumShow8; // 第8个字符显示
    m_keyLine [0] = this->lineNumShow1; // 第1个字符显示
    m_keyLine [1] = this->lineNumShow2; // 第2个字符显示
    m_keyLine [2] = this->lineNumShow3; // 第3个字符显示
    m_keyLine [3] = this->lineNumShow4; // 第4个字符显示
    m_keyLine [4] = this->lineNumShow6; // 第5个字符显示
    m_keyLine [5] = this->lineNumShow7; // 第6个字符显示
    m_keyLine [6] = this->lineNumShow8; // 第7个字符显示
    m_keyLine [7] = this->lineNumShow9; // 第8个字符显示

    showMainWindow();
    on_pushButtonClear_clicked();
    /* 默认不显示离开会议按钮 */
    pushButtonLeaveTheMeeting->setVisible(true);
    saveChildrenInfo();


    /* 获取业务调用Controller*/
    mShareServiceController = Huawei::Idea::ShareServiceController::GetInstance();
    // 初始化日志
    uint32_t logLevel = SettingDialog::getLogLevel();
    const LogInfo logInfo = {TUP_LOG_PATH,(LogLevel)logLevel,true};
    mShareServiceController->SetLog(logInfo);
    qDebug() << "init set log level: "<< logInfo.logLevel;

    // 初始化IDEASHARE SDK
    AppInfo appInfo;
    memset(&appInfo, 0, sizeof(AppInfo));
    const AppInfo *appInfoSouth = &appInfo;
    appInfo.appId = "1024"; /* 随意设置的，该值不会使用 */
    appInfo.exePath = "1024"; /* 随意设置的，该值不会使用 */
    mshareEvtHandler = new ShareEventHandler(this,mShareServiceController);
    int ret = -1;
    if (mshareEvtHandler != NULL) {
        ret = mShareServiceController->Create(appInfo,mshareEvtHandler);
    }
    if (ret != 0){
        qDebug() << "Init failed";
    }
    if (mShareServiceController != NULL) {
        qDebug() << "set cbc mode" << endl;
        // 初始化的时候这里主要是为了设置isCompatibility参数
        const SharePolicy  sharePolicy = { QUAITY_CLEAR_FIRST, false, true };
        m_isCompatibility = true;
        mShareServiceController->SetPolicy(sharePolicy);
    }
}
void MainWindow::save() {}


void MainWindow::setRemoteControlBaseVersion(bool isBase)
{
    if (isBase) {
        this->pushButtonMute->move(120 * m_rate, 66 * m_rate);                        // 置中坐标 120, 66
        this->pushButtonUnMute->move(120 * m_rate, 66 * m_rate);                      // 置中坐标 120, 66
        this->labelMicrophone->move(129 * m_rate, 158 * m_rate);                      // 置中坐标 129, 158
        this->pushButtonOpenVideo->setVisible(!isBase);
        this->pushButtonVideo->setVisible(!isBase);
    } else {
        this->pushButtonMute->move(51 * m_rate, 66 * m_rate);                         // 置左坐标 51, 66
        this->pushButtonUnMute->move(51 * m_rate, 66 * m_rate);                       // 置左坐标 51, 66
        this->labelMicrophone->move(60 * m_rate, 158 * m_rate);                       // 置左坐标 60, 158
        this->pushButtonOpenVideo->move(189 * m_rate, 66 * m_rate);                   // 置右坐标 189, 66
        this->pushButtonVideo->move(189 * m_rate, 66 * m_rate);                       // 置右坐标 189, 66
        this->labelCamera->move(198 * m_rate, 158 * m_rate);                          // 置右坐标 198, 158
    }
    this->labelCamera->setVisible(!isBase);
}
// 正常喇叭图标
void MainWindow::showMuteVoiceWindow()
{
    this->pushButtonMuter->show();
    this->pushButtonUnMuter->hide();
}
// 静音图标
void MainWindow::showUnMuteVoiceWindow()
{
    this->pushButtonMuter->hide();
    this->pushButtonUnMuter->show();
}

void MainWindow::showMuteWindow()
{
    this->pushButtonMute->show();
    this->pushButtonUnMute->hide();
}
void MainWindow::showUnMuteWindow()
{
    this->pushButtonMute->hide();
    this->pushButtonUnMute->show();
}
void MainWindow::showVideoWindow()
{
    this->pushButtonOpenVideo->hide();
    this->pushButtonVideo->show();
}
void MainWindow::showOpenVideoWindow()
{
    this->pushButtonOpenVideo->show();
    this->pushButtonVideo->hide();
}

void MainWindow::showMainWindow()
{
    if (m_isSharing) {
        m_isSharing = false;
//#if defined(IDEASHAREKEY)
//        ideasharesdk::auxreq::notifyStoped();
//#endif

#if defined(Q_OS_WIN)
        SetThreadExecutionState(ES_CONTINUOUS);
#endif
    }
    this->widgetHead->setVisible(true);
    this->widgetIdentify->setVisible(true);
    this->widgetShare->setVisible(false);
    this->widgetRemoteControl->setVisible(false);
    // 超八位暂停
    // InitUI();
#if defined(IDEASHAREKEY)
    m_isShowMainWindow = true;
    ideasharesdk::terminal::notifyDisConnected();
    this->hide();
    qDebug() << "showButtonName(Connect)";
    if (m_systray)
        m_systray->showButtonName(TheFiveButtonType::Connect);
#endif
}
void MainWindow::showRemoteControlWindow()
{
//#if defined(IDEASHAREKEY)
//    m_isShowMainWindow = false;
//    this->hide();
//#endif
    this->widgetHead->setVisible(true);
    this->widgetIdentify->setVisible(false);
    this->widgetShare->setVisible(false);
    this->widgetRemoteControl->setVisible(true);
    // 按钮自适应大小
    QFontMetrics pfont(this->pushButtonCloseRemoteControl->font());
    int wid = pfont.boundingRect(this->pushButtonCloseRemoteControl->text()).width();
    this->pushButtonCloseRemoteControl->setFixedWidth(wid + 2);       // 增添长度2
}

void MainWindow::showShareWindow()
{
#if defined(IDEASHAREKEY)
    m_isShowMainWindow = false;
    on_checkBoxMusic_clicked(ideasharesdk::config::clientplay.value());
    this->hide();
#endif
    this->widgetRemoteControl->setVisible(false);
    widgetShare->setVisible(true);
    widgetIdentify->setVisible(false);
    //  labelAddress->setText(QObject::tr("Internet:") + QString(services::terminal::ip.c_str()));
    labelAddress->setVisible(false);
    ConnectInfoShow();
#if defined(IDEASHAREKEY)
    this->pushButtonDisConnect->setVisible(false);
    this->widgetOpenRemotoControl->setVisible(false);
#endif
#if defined(Q_OS_WIN)
    /* 连接中, 取消休眠 */
    SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED | ES_AWAYMODE_REQUIRED | ES_DISPLAY_REQUIRED);
#endif
}
bool MainWindow::GetFontszie(QFont &font, QString &text, int &fontSize)
{
    if (fontSize > 0) {
        font.setPixelSize(fontSize);
    }

    labelConnectID->style()->unpolish(labelConnectID);
    labelConnectID->style()->polish(labelConnectID);
    labelConnectID->setFont(font);

    QFontMetrics fontMet = labelConnectID->fontMetrics();
    return fontMet.horizontalAdvance(text + "AA") > labelConnectID->width();
}
void MainWindow::ConnectInfoShow()
{
    QString curText = QObject::tr("Connect:")+ mDeviceName;
    QString lastText = curText;
    int frontSize = 16 * m_rate; // 基础字体16号
    QFont font = labelConnectID->font();
    if (GetFontszie(font, curText, frontSize)) {
        frontSize = 14 * m_rate; // 基础字体14号
        if (GetFontszie(font, curText, frontSize)) {
            frontSize = 12 * m_rate; // 基础字体12号
            QString tmpName;
            lastText.clear();
            for (int i = 0; i < curText.length(); i++) {
                tmpName.append(curText.at(i));
                if (GetFontszie(font, tmpName, frontSize)) {
                    tmpName += "\n";
                    lastText += tmpName;
                    tmpName.clear();
                }
            }
            if (!tmpName.isEmpty()) {
                lastText += tmpName;
                tmpName.clear();
            }
        }
    }
    labelConnectID->style()->unpolish(labelConnectID);
    labelConnectID->style()->polish(labelConnectID);
    font.setPixelSize(frontSize);
    labelConnectID->setFont(font);
    labelConnectID->setText(lastText);
}
void MainWindow::showSendWindow()
{
    m_isSharing = false;
    showShareWindow();
#if defined(IDEASHAREKEY)
    this->hide();
    bool ISKey = true;
#else
    bool ISKey = false;
#endif

    this->widgetSend->setVisible(true);
    this->widgetStop->setVisible(false);
    this->labelShare->setVisible(!ISKey);
    this->labelShareKey->setVisible(ISKey);
    this->labelShowResultShare->setVisible(!ISKey);
    this->labelShowResultShareKey->setVisible(ISKey);
}

void MainWindow::showStopWindow()
{
    m_isSharing = true;
    showShareWindow();
    this->widgetSend->setVisible(false);
    this->widgetStop->setVisible(true);

#if defined(IDEASHAREKEY)
    this->hide();
    ideasharesdk::auxreq::notifySended();
    bool ISKey = true;
#else
    bool ISKey = false;
#endif
    this->labelStop->setVisible(!ISKey);
    this->labelStopKey->setVisible(ISKey);
    this->labelShowResultStop->setVisible(!ISKey);
    this->labelShowResultStopKey->setVisible(ISKey);

    /* 投屏成功，自动隐藏 */
//    if (ideasharesdk::config::autohide.value()) {
//        this->hide();
//    }
    //this->hide();
}

void MainWindow::systray_activated(QSystemTrayIcon::ActivationReason reason)
{
#if defined(IDEASHAREKEY)
    return;
#endif
    // 判断用户对图标触摸的类型.是双击，还是点击，还是右击等等.
    switch (reason) {
        case QSystemTrayIcon::Trigger:
        case QSystemTrayIcon::DoubleClick:
        {
            this->showNormal();
            this->activateWindow();
        } break;
        default:
            break;
    }
}

void MainWindow::on_pushButtonExit_clicked()
{
    if (mShareServiceController != NULL) {
        qDebug() << "begin stop shareing" << endl;
        mShareServiceController->StopSharing();
        const SharePolicy  sharePolicy = { QUAITY_CLEAR_FIRST, false, false };
        m_isCompatibility = false;
        mShareServiceController->SetPolicy(sharePolicy);
    }

    if (mShareServiceController ) {
        mShareServiceController->Destory();
    }

    if (mshareEvtHandler) {
        delete mshareEvtHandler;
        mshareEvtHandler = nullptr;
    }

    this->close();

}
void MainWindow::on_pushButtonMore_clicked()
{
    if (m_settingMenudialog && m_settingMenudialog->isVisible()) {
        m_settingMenudialog->hide();
    } else {
        if (!m_settingMenudialog) {
            m_settingMenudialog = new (std::nothrow) SettingMenuDialog(this);
            QObject::connect(m_settingMenudialog, &SettingMenuDialog::leaveOut, this, &MainWindow::slotHideSettingMenu);
        }
        m_settingMenudialog->hide();
        m_settingMenudialog->move(this->frameGeometry().topLeft() + QPoint(30, 40) * getCurrentRate(this));  // 设置菜单栏最终位置QPoint(30, 40)
        m_settingMenudialog->m_UseCenter = true;
        m_settingMenudialog->resizeWindow();
        m_settingMenudialog->move(this->frameGeometry().topLeft() + QPoint(30, 40) * getCurrentRate(this));  // 设置菜单栏最终位置QPoint(30, 40)
        m_settingMenudialog->show();
        m_settingMenudialog->m_UseCenter = false;
        m_settingMenudialog->activateWindow();
    }
}

void MainWindow::on_pushButtonShare_clicked()
{
#if defined(IDEASHAREKEY)
    m_toastdialog->showSharing();
    ideasharesdk::auxreq::send();
#endif

#if !defined(IDEASHAREKEY)
    if (!m_isSendingRequest) {
        m_isSendingRequest = true;
        this->m_sendTimer->start();
        this->pushButtonShare->setEnabled(false);
        this->pushButtonStop->setEnabled(false);
        if (mShareServiceController != NULL) {
            mShareServiceController->StartSharing();
        }
    }
#endif
}
void MainWindow::on_pushButtonStop_clicked()
{
#if defined(IDEASHAREKEY)
    ideasharesdk::auxreq::stop();
#endif

#if !defined(IDEASHAREKEY)
    if (!m_isSendingRequest) {
        m_isSendingRequest = true;
        this->m_sendTimer->start();
        this->pushButtonShare->setEnabled(false);
        this->pushButtonStop->setEnabled(false);
        if (mShareServiceController != NULL) {
          mShareServiceController->StopSharing();
        }
    }
#endif
}

void MainWindow::on_pushButtonNum0_clicked()
{
    QKeyEvent keyEvent(QEvent::KeyPress, Qt::Key_0, Qt::NoModifier);
    QCoreApplication::sendEvent(this, &keyEvent);
}
void MainWindow::on_pushButtonNum1_clicked()
{
    QKeyEvent keyEvent(QEvent::KeyPress, Qt::Key_1, Qt::NoModifier);
    QCoreApplication::sendEvent(this, &keyEvent);
}
void MainWindow::on_pushButtonNum2_clicked()
{
    QKeyEvent keyEvent(QEvent::KeyPress, Qt::Key_2, Qt::NoModifier);
    QCoreApplication::sendEvent(this, &keyEvent);
}
void MainWindow::on_pushButtonNum3_clicked()
{
    QKeyEvent keyEvent(QEvent::KeyPress, Qt::Key_3, Qt::NoModifier);
    QCoreApplication::sendEvent(this, &keyEvent);
}
void MainWindow::on_pushButtonNum4_clicked()
{
    QKeyEvent keyEvent(QEvent::KeyPress, Qt::Key_4, Qt::NoModifier);
    QCoreApplication::sendEvent(this, &keyEvent);
}
void MainWindow::on_pushButtonNum5_clicked()
{
    QKeyEvent keyEvent(QEvent::KeyPress, Qt::Key_5, Qt::NoModifier);
    QCoreApplication::sendEvent(this, &keyEvent);
}
void MainWindow::on_pushButtonNum6_clicked()
{
    QKeyEvent keyEvent(QEvent::KeyPress, Qt::Key_6, Qt::NoModifier);
    QCoreApplication::sendEvent(this, &keyEvent);
}
void MainWindow::on_pushButtonNum7_clicked()
{
    QKeyEvent keyEvent(QEvent::KeyPress, Qt::Key_7, Qt::NoModifier);
    QCoreApplication::sendEvent(this, &keyEvent);
}
void MainWindow::on_pushButtonNum8_clicked()
{
    QKeyEvent keyEvent(QEvent::KeyPress, Qt::Key_8, Qt::NoModifier);
    QCoreApplication::sendEvent(this, &keyEvent);
}
void MainWindow::on_pushButtonNum9_clicked()
{
    QKeyEvent keyEvent(QEvent::KeyPress, Qt::Key_9, Qt::NoModifier);
    QCoreApplication::sendEvent(this, &keyEvent);
}
void MainWindow::on_pushButtonDelete_clicked()
{
    QKeyEvent keyEvent(QEvent::KeyPress, Qt::Key_Backspace, Qt::NoModifier);
    QCoreApplication::sendEvent(this, &keyEvent);
}
void MainWindow::on_pushButtonClear_clicked()
{
    for (int index = 0; index < 8; ++index) { // 8个按钮
        m_keyLine [index]->setStyleSheet("QFrame{background-color:#B7B7B7;border:none;max - height:1px;border - radius: 1.09px;}");
    }
    showKeyNumCount();
    for (auto &g : keyLabels) {
        g->clear();
    }
}
void MainWindow::on_checkBoxMusic_clicked(bool on)
{
    qDebug() << "on_checkBoxMusic_clicked on = "<<on;
    if (mShareServiceController != NULL) {
        const SharePolicy  sharePolicy = { QUAITY_CLEAR_FIRST, on, m_isCompatibility };
       // m_isCompatibility = false;
        mShareServiceController->SetPolicy(sharePolicy);
    }
#if defined(IDEASHAREKEY)
    if (on) {
        qDebug() << "showButtonNmae(StopShareAudio)";
        if (m_systray)
            m_systray->showButtonName(TheFiveButtonType::StopShareAudio);
    } else {
        qDebug() << "showButtonNmae(ShareAudio)";
        if (m_systray)
            m_systray->showButtonName(TheFiveButtonType::ShareAudio);
    }
#endif
}
void MainWindow::on_pushButtonChooseKeyNum_clicked()
{
    m_useSixKeyNum = !m_useSixKeyNum;
    showKeyNumCount();
    for (int index = 0; index < 8; ++index) { // 8个按钮
        m_keyLine [index]->setStyleSheet("QFrame{background-color:#B7B7B7;;border:none;max - height:1px;border - radius: 1.09px;}");
    }
    for (auto &g : keyLabels) {
        g->clear();
    }
}
void MainWindow::showKeyNumCount()
{
    keyLabels [0]->setVisible(!m_useSixKeyNum); // 第0个按钮
    keyLabels [7]->setVisible(!m_useSixKeyNum); // 第7个数字显示
    this->lineNumShow1->setVisible(!m_useSixKeyNum);
    this->lineNumShow9->setVisible(!m_useSixKeyNum);
    pushButtonChooseKeyNum->setText(QObject::tr("     %1digits").arg(m_useSixKeyNum ? 8 : 6)); // 设置用8或者6位投屏码
    m_currentIndex = m_useSixKeyNum ? 1 : 0; // 初始第0或者1个作为首位码
}

void MainWindow::slotpushButtonLogInfo()
{
    if (m_collectlogdialog == nullptr) {
        m_collectlogdialog = new (std::nothrow) CollectLogDialog(this);
        connect(this, SIGNAL(closeCollectLogDialog()), m_collectlogdialog, SLOT(hide()));
    }
    if (m_collectlogdialog) {
#if !defined(IDEASHAREKEY)
        this->showNormal();
        this->activateWindow();
#endif
        //ideasharesdk::log::collect();
        m_collectlogdialog->hide();
        m_collectlogdialog->m_UseCenter = true;
        m_collectlogdialog->move(geometry().center() - m_collectlogdialog->rect().center());
        m_collectlogdialog->resizeWindow();
        m_collectlogdialog->move(geometry().center() - m_collectlogdialog->rect().center());
        m_collectlogdialog->activateWindow();
        m_collectlogdialog->m_UseCenter = false;
        m_collectlogdialog->show();
    }
}
void MainWindow::slotHideSettingMenu()
{
    if (m_settingMenudialog && m_settingMenudialog->isVisible()) {
        m_settingMenudialog->hide();
    }
}
void MainWindow::slotpushButtonSetting()
{
    if (m_settingdialog == nullptr) {
        m_settingdialog = new (std::nothrow) SettingDialog(this);
    }
    if (m_settingdialog) {

#if !defined(IDEASHAREKEY)
        this->showNormal();
        this->activateWindow();
#endif
        m_settingdialog->hide();
        m_settingdialog->m_UseCenter = true;
        m_settingdialog->screenShot();
        m_settingdialog->move(geometry().center() - m_settingdialog->rect().center());
        m_settingdialog->resizeWindow();
        m_settingdialog->move(geometry().center() - m_settingdialog->rect().center());
        m_settingdialog->activateWindow();
        m_settingdialog->m_UseCenter = false;
        m_settingdialog->show();
    }
}
void MainWindow::slotpushButtonAbout()
{
    if (m_aboutdialog == nullptr) {
        m_aboutdialog = new (std::nothrow) AboutDialog(this);
    }
    if (m_aboutdialog) {
#if !defined(IDEASHAREKEY)
        this->showNormal();
        this->activateWindow();
#endif
        m_aboutdialog->hide();
        m_aboutdialog->move(geometry().center() - m_aboutdialog->rect().center());
        m_aboutdialog->m_UseCenter = true;
        m_aboutdialog->resizeWindow();
        m_aboutdialog->m_UseCenter = false;
        m_aboutdialog->move(geometry().center() - m_aboutdialog->rect().center());
        m_aboutdialog->activateWindow();
        m_aboutdialog->show();
    }
}

void MainWindow::slotpushButtonSetCode()
{
    if (m_setCodeialog == nullptr) {
        m_setCodeialog = new (std::nothrow) ServerDialog(this);
        m_setCodeialog->resize(m_setCodeialog->size());
    }
    if (m_setCodeialog) {
#if !defined(IDEASHAREKEY)
        this->showNormal();
        this->activateWindow();
#endif
        m_setCodeialog->hide();
        m_setCodeialog->move(geometry().center() - m_setCodeialog->rect().center());
        m_setCodeialog->m_UseCenter = true;
        m_setCodeialog->resizeWindow();
        m_setCodeialog->move(geometry().center() - m_setCodeialog->rect().center());
        m_setCodeialog->m_UseCenter = false;
        m_setCodeialog->activateWindow();
        m_setCodeialog->show();
    }
}
void MainWindow::keyPressEvent(QKeyEvent *event)
{
    if (frameErrorInfo->isVisible())
        return;
    if (m_waitTimer->isActive())
        return;
    if (!this->widgetIdentify->isVisible())
        return;
    if ((event->key() == Qt::Key_Delete) || (event->key() == Qt::Key_Backspace)) {
        if (m_currentIndex > (m_useSixKeyNum ? 1 : 0)) {
            m_currentIndex--;
            keyLabels [m_currentIndex]->clear();
            m_keyLine [m_currentIndex]->setStyleSheet("QFrame{background-color:#B7B7B7;;border:none;max - height:1px;border - radius: 1.09px;}");
        }
    } else if (((event->key() >= Qt::Key_A) && (event->key() <= Qt::Key_Z)) ||
        ((event->key() >= Qt::Key_0) && (event->key() <= Qt::Key_9))) {
#ifdef __APPLE__
        QString str(event->key());
#else
        QString str(event->key());
#endif
        keyLabels [m_currentIndex]->setText(str);
        m_keyLine [m_currentIndex]->setStyleSheet("QFrame{background-color:#0D94FF;border:none;max - height:1px;border - radius: 1.09px;}");
        m_currentIndex++;

        int limitKeys = m_useSixKeyNum ? 7 : 8; // 设置最大字符数字7或者8
        if (m_currentIndex >= limitKeys) {
            QString text = {};
            for (auto &g : keyLabels) {
                if (g->isVisible()) {
                    text += g->text();
                }
            }
            labelWaitSign->setVisible(true);
             m_waitTimer->start();
#if !defined(IDEASHAREKEY)
            m_connectTimeoutTimer->start();
#endif
            //查询本地投影码
            qDebug() << "start discover";
            if (mShareServiceController != NULL) {
                if (!SettingDialog::getEuaIP().isEmpty()) {
                    string address = SettingDialog::getEuaIP().toStdString();
                    uint32_t euaPort = SettingDialog::getEuaPort();
                    mShareServiceController->Discover(text.toStdString(),address,euaPort);
                }
                else {
                    mShareServiceController->Discover(text.toStdString(),"",0);
                }
                text.clear();
                showKeyNumCount();
            }

        }
    }
}
void MainWindow::on_pushButtonDisConnect_clicked()
{
    ReConfirmation rec(this);
#if defined(Q_OS_WIN)
    rec.SetTextAndLoge(QString("Disconnected ?"),  QString(":/image/images/96.png"));
#else
    QString text = QObject::tr("Disconnected ?");
    QString imageName = QString(":/image/images/96.png");
    rec.SetTextAndLoge(text, imageName);
#endif
    rec.move(geometry().center() - rec.rect().center());
    rec.resizeWindow();
    rec.move(geometry().center() - rec.rect().center());
    if (rec.exec()) {
        //ideasharesdk::terminal::disconnect();
        qDebug() << "start disconnect";
        if (mShareServiceController != NULL) {
           qDebug() << "before disconnect";
           mShareServiceController->Disconnect();
            qDebug() << "end disconnect";
        }
    }
}

void MainWindow::showEvent(QShowEvent *event)
{
    this->setAttribute(Qt::WA_Mapped);
    QWidget::showEvent(event);
}
void MainWindow::paintEvent(QPaintEvent *event)
{
    QPoint aimPt = this->pushButtonDisConnect->pos();
    int width = pushButtonDisConnect->width();
    QFontMetrics fmnotice(pushButtonDisConnect->font());
    int wid = fmnotice.boundingRect(pushButtonDisConnect->text()).width();
    pushButtonDisConnect->setFixedWidth(wid + 12); // 文字边距12
    int deltaW = width - wid - 12;  // 文字边距12
    aimPt.setX(aimPt.x() + deltaW);
    this->pushButtonDisConnect->move(aimPt);
    QPainter painter(this);
    // 反走样
    painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform |
                           QPainter::HighQualityAntialiasing);

    QStyleOption opt;
    opt.init(this);
    QPainter p(this);
    style()->drawPrimitive(QStyle::PE_FrameWindow, &opt, &p, this);
}

/* ------- 终端会议遥控相关 ------------------ */
/* ------- 点击触发静音 ------------------ */
void MainWindow::on_pushButtonMute_clicked()
{
    qDebug() << "mute the mic....";
    QPoint mous = this->pushButtonMute->pos() + QPoint(50, 50) * getCurrentRate(this); // 按键中心相对坐标QPoint(50, 50)
    QPoint mousepoint =
        mapFromGlobal(cursor().pos()) - QPoint(10, 50) * getCurrentRate(this);         // 鼠标中心相对坐标QPoint(10, 50)
    double Radius = 36.0 * getCurrentRate(this);                                       // 最大允许半径36.0
    if (this->isPointInCircle(mousepoint, mous, Radius)) {
        if (mShareServiceController != NULL) {
            qDebug() << "SetRemoteMicMute true";
            mShareServiceController->SetRemoteMicMute(true);
        }
    }
}
/* ------- 点击取消静音 ------------------ */
void MainWindow::on_pushButtonUnMute_clicked()
{
    qDebug() << "unmute the mic....";
    QPoint mous =
        this->pushButtonUnMute->pos() + QPoint(50, 50) * getCurrentRate(this); // 按键中心相对坐标QPoint(50, 50)
    QPoint mousepoint =
        mapFromGlobal(cursor().pos()) - QPoint(10, 50) * getCurrentRate(this); // 鼠标中心相对坐标QPoint(10, 50)
    double Radius = 36.0 * getCurrentRate(this);                                                                   // 最大允许半径36.0
    if (this->isPointInCircle(mousepoint, mous, Radius)) {
         if (mShareServiceController != NULL) {
             qDebug() << "SetRemoteMicMute false";
             mShareServiceController->SetRemoteMicMute(false);
         }
    }
}
void MainWindow::on_pushButtonOpenVideo_clicked()
{
    QPoint mous =
        this->pushButtonOpenVideo->pos() + QPoint(50, 50) * getCurrentRate(this); // 按键中心相对坐标QPoint(50, 50)
    QPoint mousepoint =
        mapFromGlobal(cursor().pos()) - QPoint(10, 50) * getCurrentRate(this); // 鼠标中心相对坐标QPoint(10, 50)
    double Radius = 36.0 * getCurrentRate(this);                                                                   // 最大允许半径36.0
    if (this->isPointInCircle(mousepoint, mous, Radius)) {
        qDebug() << "open camera...";
        if (mShareServiceController != NULL) {
          mShareServiceController->SetRemoteCameraMute(false);
        }
    }
}
void MainWindow::on_pushButtonVideo_clicked()
{
    QPoint mous = this->pushButtonVideo->pos() + QPoint(50, 50) * getCurrentRate(this); // 按键中心相对坐标QPoint(50, 50)
    QPoint mousepoint =
        mapFromGlobal(cursor().pos()) - QPoint(10, 50) * getCurrentRate(this); // 鼠标中心相对坐标QPoint(10, 50)
    double Radius = 36.0 * getCurrentRate(this);                                                                   // 最大允许半径36.0
    if (this->isPointInCircle(mousepoint, mous, Radius)) {
        qDebug() << "close camera...";
       if (mShareServiceController != NULL) {
         mShareServiceController->SetRemoteCameraMute(true);
       }
    }
}
void MainWindow::on_pushButtonLeaveTheMeeting_clicked()
{
    TIPTYPE_E mode =  mIsChairMan ? TIPTYPE_E::IDERSHARE_MEET : TIPTYPE_E::IDEASHARE_NOMAL;
    qDebug() << "TheMeeting_clicked:hoststatus:" << mIsChairMan;
    ReConfirmation rec(this, mode);

#if defined(Q_OS_WIN)
    rec.SetTextAndLoge(QObject::tr("Are you sure you want to leave the conference? "),
                       QString(":/image/images/124.png"));
#else
    QString text = QObject::tr("Are you sure you want to leave the conference? ");
    QString imageName = QString(":/image/images/124.png");
    rec.SetTextAndLoge(text, imageName);
#endif
    rec.move(geometry().center() - rec.rect().center());
    rec.resizeWindow();
    rec.move(geometry().center() - rec.rect().center());
    if (mShareServiceController == NULL) {
        return;
    }
    if (rec.exec()) {
        if (mode == TIPTYPE_E::IDERSHARE_MEET && rec.GetCheckboxVisibleStatus()) {
          mShareServiceController->EndConference();
        } else {
          mShareServiceController->LeaveConference();
        }
    }
}
void MainWindow::on_pushButtonMuter_clicked()
{
    qDebug() << "mute the speaker....";
    if (mVolume == 0) {
      qDebug() << "volume is zero, so mute return";
      return;
    }
    if (mShareServiceController != NULL) {
        mShareServiceController->SetRemoteSpeakerMute(true);
    }
}
void MainWindow::on_pushButtonUnMuter_clicked()
{   qDebug() << "umute the speaker....";
    if (mVolume == 0) {
      qDebug() << "volume is zero, so unmute return";
      return;
    }
    if (mShareServiceController != NULL) {
        mShareServiceController->SetRemoteSpeakerMute(false);
    }
}
void MainWindow::on_pushButtonOpenRemoteControl_clicked()
{
    /* 查询终端 麦克风 摄像头 等 状态 */
    qDebug() << "query micstatus camstatus voicestatus volume...";
    //ideasharesdk::conference::query();
    if (mShareServiceController != NULL) {
        mShareServiceController->GetRemoteServiceStatus();
    }
}
void MainWindow::on_pushButtonCloseRemoteControl_clicked()
{
    showShareWindow();
}
void MainWindow::on_pushButtonCloseRemote_clicked()
{
    on_pushButtonCloseRemoteControl_clicked();
}

/*  > 三角箭头槽函数 */
void MainWindow::on_pushButtonRemote_clicked()
{
    on_pushButtonOpenRemoteControl_clicked();
}
/* ------------------------------------------ */
bool MainWindow::eventFilter(QObject *watched, QEvent *event)
{
    if (watched == this->horizontalSliderVolume && event->type() == QEvent::MouseButtonRelease) {
        onSliderMouseLButtonPress(watched, event);
        int value = valueRangeConversion(this->horizontalSliderVolume->value(), 1);
        qDebug() << "set volume value = " << value;
        if (mShareServiceController != NULL) {
            mShareServiceController->SetRemoteSpeakerVolume(value);
        }
    }
    return QObject::eventFilter(watched, event);
}


uint32_t MainWindow::valueRangeConversion(uint32_t value, uint32_t type)
{
    /* 两端的余量 为 1 给 0 和 21 预留 */
    qDebug() << "valueRangeConversion in";
    uint32_t maxRange = this->horizontalSliderVolume->maximum();
    uint32_t maxRangeValue = 21;  // 音量最大21
    int result = 0;
    double steplenth = maxRange * 1.0 / (maxRangeValue - 1.0);    // 1.0 化成double型
    if (type == 0) {
         qDebug() << "type == 0";
        /* 0 - 21 转 1 - 203 */
        if (value >= maxRangeValue)
            return maxRange; // 数值大于最大201
        if (value <= 0)
            return 0;
        result = (value - 1) * steplenth + steplenth / 2.0; // 2.0取半值 1起步值
    } else {
        qDebug() << "type != 0";
        /* 1 - 203 转 0 - 21 */
        if (value <= 0)   // 2.0 取半值
            return 0;
        if (value >= maxRange) // 2.0取半值
            return maxRangeValue;                 // 返回结果调整21
        result = value / steplenth + 1; // 2.0取半值  // 1起步值
    }
    qDebug() << "valueRangeConversion out";
    return result;
}
/* 处理滑块释放事件 */
void MainWindow::onSliderMouseLButtonPress(QObject *slider, QEvent *event)
{
    do {
        // 只处理 鼠标左键 的按下事件
        QSlider *sliderCtrl = static_cast<QSlider *>(slider);
        QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
        if (Qt::LeftButton != mouseEvent->button()) {
            break;
        }

        // 确定控件操作的基本参数
        int cxctl = 0; // 滑块宽度
        int cxwnd = 0; // 滑槽长度
        int mxpos = 0; // 鼠标按下的位置

        if (Qt::Horizontal == sliderCtrl->orientation()) {
            // 水平样式的 slider
            cxctl = sliderCtrl->minimumSizeHint().width();
            cxwnd = sliderCtrl->width();
            if (sliderCtrl->invertedAppearance())
                mxpos = cxwnd - mouseEvent->x();
            else
                mxpos = mouseEvent->x();
        } else {
            // 垂直样式的 slider
            cxctl = sliderCtrl->minimumSizeHint().height();
            cxwnd = sliderCtrl->height();
            if (sliderCtrl->invertedAppearance())
                mxpos = mouseEvent->y();
            else
                mxpos = cxwnd - mouseEvent->y();
        }
        if (cxwnd <= cxctl) {
            break;
        }

        // 计算结果，并设置新计算得到的 position 值
        int scpos = sliderCtrl->minimum() + (int)((sliderCtrl->maximum() - sliderCtrl->minimum()) *
            ((mxpos - cxctl / 2.0) / (cxwnd - cxctl))); // 获取半值除以2.0

        int left = sliderCtrl->sliderPosition() - cxctl / 2;                // 获取半值除以2
        int right = sliderCtrl->sliderPosition() + cxctl / 2;               // 获取半值除以2
        if (left <= scpos && scpos <= right) {
            break;
        }

        sliderCtrl->setSliderPosition(scpos);
    } while (0);
}


/* 处理底层反馈信息到界面的映射 */
void MainWindow::handleConnectRet(bool result, IDEASHARE_ERROR_ID errcode)
{
    m_waitTimer->stop();
#if !defined(IDEASHAREKEY)
    m_connectTimeoutTimer->stop();
#endif
    this->labelWaitSign->setVisible(false);
    this->frameErrorInfo->setVisible(false);
    if (result) {
        /* 清空投屏码 */
        on_pushButtonClear_clicked();
        /* 显示 分享界面 */
#if defined(IDEASHAREKEY)
        m_toastdialog->handleConnectSuccess();
#endif
        showSendWindow();
        m_isSharing = false;
    } else {
#if defined(IDEASHAREKEY)
        qDebug() << "show toast disconnect ...";
        if (m_toastdialog != nullptr) {
            if (errcode == IDEASHARE_ERROR_CONNECT_BUSY || errcode == IDEASHARE_ERROR_MULTICONNECT_TERMINAL_BUSY) {
                m_toastdialog->handleConnectBusy();
            } else if (errcode == IDEASHARE_ERROR_IN_CONNECTION) {
                m_toastdialog->handleConnectSuccess();
            } else {
                m_toastdialog->handleConnectFailed();
            }
        }
#else
        if (errcode != IDEASHARE_ERROR_SUCCESS) {
            /* 显示 错误码 */
            this->frameErrorInfo->setVisible(true);
//            this->labelResultInfo->setText(strerrno(errcode));
            this->m_errorTimer->start();
        }
#endif
    }
}
void MainWindow::handleDisConnectRet(bool result, IDEASHARE_ERROR_ID errcode)
{
    if (result) {
        qDebug() << "disconnect ret.";
        showMainWindow();
#if defined(IDEASHAREKEY)
        if (m_toastdialog != nullptr) {
            qDebug() << "show toast disconnect ...";
            m_toastdialog->handleDisConnectAndRetry();
        }
#endif // IDEASHAREKEY
    } else {
//        qDebug() << strerrno(errcode);
    }
}
void MainWindow::handleSendAuxRet(bool result, IDEASHARE_ERROR_ID errcode)
{
    if (!result) {
        /* 显示 错误码 */
        this->frameErrorInfo->setVisible(true);
//        this->labelResultInfo->setText(strerrno(errcode));
        this->m_errorTimer->start();
        qDebug() << "send error...";
#if defined(IDEASHAREKEY)
        m_toastdialog->showShareFiled(errcode);
#endif
    }
}
void MainWindow::handleStopAuxRet(bool result, IDEASHARE_ERROR_ID errcode)
{
    if (result) {
        if (m_isSharing == true) {
            showSendWindow();
#if defined(IDEASHAREKEY)
            m_toastdialog->showShareStop();
#endif
        }
    } else {
        /* 显示 错误码 */
        this->frameErrorInfo->setVisible(true);
//        this->labelResultInfo->setText(strerrno(errcode));
        this->m_errorTimer->start();
        qDebug() << "stop error...";
    }
}
void MainWindow::handleCollectLogRet(bool result, IDEASHARE_ERROR_ID errcode)
{
    qDebug() << "recive collect log reslut...";
    /*  关闭日志采集窗口 */
    emit closeCollectLogDialog();
    if (result) {
//        QString url = stdWToQString(ideasharesdk::log::url.c_str());
//        int position = url.lastIndexOf("\\");
//        qDebug() << "handleCollectLogRet collect log reslut... url"<< url;
//        bool retValue = QDesktopServices::openUrl(QUrl::fromLocalFile(url.left(position + 1)));
//        qDebug() << "closeCollectLogDialog log return..."<< retValue;
    } else {
        qDebug() << "collect log error...";
    }
}
void MainWindow::handleDisConnectFromTerm(bool result, IDEASHARE_ERROR_ID errcode)
{
    /* 断开连接 */
    if (result) {
        qDebug() << "disconnect form term.";
        showMainWindow();
        /* 显示 错误码 */
        this->frameErrorInfo->setVisible(true);
//        this->labelResultInfo->setText(strerrno(errcode));
        this->m_errorTimer->start();
#if defined(IDEASHAREKEY)
        if (m_toastdialog != nullptr) {
            qDebug() << "show toast disconnect ...";
            m_toastdialog->handleDisConnectAndRetry();
        }
#endif // IDEASHAREKEY
    } else {
//        qDebug() << strerrno(errcode);
    }
}
void MainWindow::handleSendAuxStatus(bool result, IDEASHARE_ERROR_ID errcode)
{
    if (result) {
        if (m_isSharing == false) {
            showStopWindow();
#if defined(IDEASHAREKEY)
            m_toastdialog->showShareSuccess();
#endif
        }
    } else {
        qDebug() << "sendaux error...";
    }
}
void MainWindow::handleTerminalInfo(bool result, IDEASHARE_ERROR_ID errcode)
{
    if (result) {
        qDebug() << "connect success...";
    }
}
void MainWindow::handleUpgrageInfo(bool result, IDEASHARE_ERROR_ID errcode)
{
    /* 升级弹框提示 */
    if (m_upgradedialog == nullptr) {
        m_upgradedialog = new Upgradedialog(this);
    }
    if (m_upgradedialog != nullptr) {
        m_upgradedialog->move(geometry().center() - m_upgradedialog->rect().center());
        m_upgradedialog->m_UseCenter = true;
        m_upgradedialog->resizeWindow();
        m_upgradedialog->move(geometry().center() - m_upgradedialog->rect().center());
        m_upgradedialog->m_UseCenter = false;
        m_upgradedialog->show();
    }
}
void MainWindow::handleCertUpdate(bool result, IDEASHARE_ERROR_ID errcode)
{
    if (!result) {
        if (m_certUpdatedialog == nullptr) {
            m_certUpdatedialog = new CertUpdateDialog(this);
        }
        if (m_certUpdatedialog != nullptr) {
            m_certUpdatedialog->move(geometry().center() - m_certUpdatedialog->rect().center());
            m_certUpdatedialog->m_UseCenter = true;
            m_certUpdatedialog->resizeWindow();
            m_certUpdatedialog->move(geometry().center() - m_certUpdatedialog->rect().center());
            m_certUpdatedialog->m_UseCenter = false;
            m_certUpdatedialog->show();
        }
    }
}
void MainWindow::handleSupportConferenceCtrlRet(bool result, IDEASHARE_ERROR_ID errcode)
{
    pushButtonOpenRemoteControl->setVisible(result);
    pushButtonRemote->setVisible(result);
}
void MainWindow::handleConferenceCtrlRet(bool result, IDEASHARE_ERROR_ID errcode)
{
//    using namespace ideasharesdk;

//    int criterion = valueRangeConversion(horizontalSliderVolume->value(), 1);
//    if (conference::volume != criterion)
//        this->horizontalSliderVolume->setValue(valueRangeConversion(conference::volume.value(), 0));

//    if (conference::voicestatus == true) {
//        showMuteVoiceWindow();
//    } else {
//        showUnMuteVoiceWindow();
//    }
//    if (conference::camstatus == true) {
//        showVideoWindow();
//    } else {
//        showOpenVideoWindow();
//    }
//    if (conference::micstatus == true) {
//        showMuteWindow();
//    } else {
//        showUnMuteWindow();
//    }
    
//    setRemoteControlBaseVersion(conference::baseversion.value());

//    qDebug() << "set confstatus :" << conference::confstatus.value();
//    this->pushButtonLeaveTheMeeting->setVisible(conference::confstatus.value());
//    showRemoteControlWindow();
}
void MainWindow::handleConferenceCtrlUpdateRet(bool result, IDEASHARE_ERROR_ID errcode)
{
//    using namespace ideasharesdk;
//    int type = errcode;
//    switch (type) {
//        case 0: // 0 麦克风状态
//        {
//            if (conference::micstatus == true) {
//                showMuteWindow();
//            } else {
//                showUnMuteWindow();
//            }
//        } break;
//        case 1: // 1 摄像头状态
//        {
//            if (conference::camstatus == true) {
//                showVideoWindow();
//            } else {
//                showOpenVideoWindow();
//            }
//        } break;
//        case 2: // 2 音量
//        {
//            int criterion = valueRangeConversion(horizontalSliderVolume->value(), 1);
//            if (conference::volume != criterion)
//                this->horizontalSliderVolume->setValue(valueRangeConversion(conference::volume.value(), 0));
//        } break;
//        case 3: // 3 会议状态
//        {
//            qDebug() << "set confstatus :" << conference::confstatus.value();
//            this->pushButtonLeaveTheMeeting->setVisible(conference::confstatus.value());
//        } break;
//        case 4: // 4 扬声器状态
//        {
//            if (conference::voicestatus == true) {
//                showMuteVoiceWindow();
//            } else {
//                showUnMuteVoiceWindow();
//            }
//        } break;
//        default:
//        {
//            qDebug() << "update conference ctrl status unknow type : " << type;
//        }
//    }


}
#if defined(IDEASHAREKEY)
void MainWindow::handleKeyClickSignal(bool result, IDEASHARE_ERROR_ID errcode)
{
    if (m_isSharing) {
        on_pushButtonStop_clicked();
    } else {
        on_pushButtonShare_clicked();
    }
}
void MainWindow::handleUsbBrokenSignal(bool result, IDEASHARE_ERROR_ID errcode)
{
    if (m_toastdialog != nullptr) {
        qDebug() << "show toast disconnect and ...";
        m_toastdialog->handleDisConnectAndExit();
    }
}
void MainWindow::handleKeyConnectRet(bool result, IDEASHARE_ERROR_ID errcode)
{
    qDebug() << "result : " << result << " errcode :" << errcode;
    if (m_toastdialog != nullptr && result == false) {
        qDebug() << "show toast disconnect and exit...";
        m_toastdialog->handleConnectFailed();
    }
}
void MainWindow::handleKeyWifiStateRet(bool result, IDEASHARE_ERROR_ID errcode)
{
    if (result == false) {
        showMainWindow();
        m_toastdialog->handleConnectFailed();
    }
}
void MainWindow::handleKeyUnpairSignal(bool result, IDEASHARE_ERROR_ID errcode)
{
    qDebug() << "handle key unpair signal...";
}
#endif
/* 处理底层反馈信息到界面的映射 */
void MainWindow::messageHandler(uint32_t msgid, bool result, uint32_t errcode)
{
    qDebug() << "msgid :" << msgid << "result : " << result << " coast : " << errcode;
//    using namespace ideasharesdk;
//    using namespace std::placeholders;
//    static QMap<IDEASHARE_MSG_ID, std::function<void(bool, IDEASHARE_ERROR_ID)>> message_handler_maper = {
//        { IDEASHARE_MSG_CONNECT_RET, std::bind(&MainWindow::handleConnectRet, this, _1, _2) },
//        { IDEASHARE_MSG_DISCONNECT_RET, std::bind(&MainWindow::handleDisConnectRet, this, _1, _2) },
//        { IDEASHARE_MSG_SEND_AUX_RET, std::bind(&MainWindow::handleSendAuxRet, this, _1, _2) },
//        { IDEASHARE_MSG_STOP_AUX_RET, std::bind(&MainWindow::handleStopAuxRet, this, _1, _2) },
//        { IDEASHARE_MSG_COLLECT_LOG_RET, std::bind(&MainWindow::handleCollectLogRet, this, _1, _2) },
//        { IDEASHARE_MSG_DISCONNECT_FROM_TERM, std::bind(&MainWindow::handleDisConnectFromTerm, this, _1, _2) },
//        { IDEASHARE_MSG_SEND_AUX_STATUS, std::bind(&MainWindow::handleSendAuxStatus, this, _1, _2) },
//        { IDEASHARE_MSG_TERMINAL_INFO, std::bind(&MainWindow::handleTerminalInfo, this, _1, _2) },
//#if !defined(IDEASHAREKEY)
//        { IDEASHARE_MSG_UPGRADE_INFO, std::bind(&MainWindow::handleUpgrageInfo, this, _1, _2) },
//#endif
//        { IDEASHARE_MSG_CERT_VERIFY_RET, std::bind(&MainWindow::handleCertUpdate, this, _1, _2) },
//        { IDEASHARE_MSG_SUPPORT_CONFERENCE_CTRL_RET, std::bind(&MainWindow::handleSupportConferenceCtrlRet, this, _1, _2) },
//        { IDEASHARE_MSG_CONF_CTRL_RET, std::bind(&MainWindow::handleConferenceCtrlRet, this, _1, _2) },
//        { IDEASHARE_MSG_CONF_CTRL_UPDATE_RET, std::bind(&MainWindow::handleConferenceCtrlUpdateRet, this, _1, _2) },
//        { IDEASHARE_MSG_CONF_STATUS_RET, [this] (bool result, uint32_t errcode) { this->pushButtonLeaveTheMeeting->setVisible(conference::confstatus.value()); } },
//#if defined(IDEASHAREKEY)
//        { IDEASHARE_MSG_KEY_CLICK_SIGNAL, std::bind(&MainWindow::handleKeyClickSignal, this, _1, _2) },
//        { IDEASHARE_MSG_USB_CHANNEL_BROKEN, std::bind(&MainWindow::handleUsbBrokenSignal, this, _1, _2) },
//        { IDEASHARE_MSG_KEY_CONNECT_RET, std::bind(&MainWindow::handleKeyConnectRet, this, _1, _2) },
//        { IDEASHARE_MSG_WIFI_STATE_RET, std::bind(&MainWindow::handleKeyWifiStateRet, this, _1, _2) },
//        { IDEASHARE_MSG_KEY_UNPAIR_SIGNAL, std::bind(&MainWindow::handleKeyUnpairSignal, this, _1, _2) },
//#endif
//    };
//    IDEASHARE_MSG_ID msg_id = (IDEASHARE_MSG_ID)msgid;
//    if (message_handler_maper.contains(msg_id)) {
//        message_handler_maper [msg_id](result, (IDEASHARE_ERROR_ID)errcode);
//    } else {
//        qDebug() << "##################### unkonw msg id. #######################";
//    }
}
bool MainWindow::clickMorePushbutton()
{
    return !this->pushButtonMore->geometry().contains(mapFromGlobal(cursor().pos()) - QPoint(10, 10) * getCurrentRate(this)); // 返回不在有效范围 QPoint(10, 10)
}
void MainWindow::resizeWindow()
{
    HWDialog::resizeWindow();
    if (m_settingdialog != nullptr && m_settingdialog->isVisible()) {
        m_settingdialog->setBuleBoder();
    }
    if (!m_isMoveWindow) {
        QScreen *src = QApplication::screenAt(this->geometry().center());
        if (src != nullptr) {
            QPoint pt = src->geometry().center();
            this->move(pt - this->rect().center());
        } else {
            QPoint pt = QApplication::desktop()->geometry().center();
            this->move(pt - this->rect().center());
        }
    }
    if (this->widgetShare->isVisible()) {
        ConnectInfoShow();
    }
    if (m_systray != nullptr) {
        m_systray->init();
    }
    if (this->widgetRemoteControl->isVisible()) {
        //setRemoteControlBaseVersion(ideasharesdk::conference::baseversion.value());
    }
}
bool MainWindow::isPointInCircle(QPoint &aimPoint, QPoint &Center, double &radius)
{
    double dist = std::sqrtf((aimPoint.x() - Center.x()) * (aimPoint.x() - Center.x()) +
        (aimPoint.y() - Center.y()) * (aimPoint.y() - Center.y()));
    return radius > dist;
}
/* ------------------------- IDEASHAREKEY ---------------------- */
#if defined(IDEASHAREKEY)
bool MainWindow::showIdeaShareKey()
{
    if (m_toastdialog == nullptr) {
        m_toastdialog = new (std::nothrow) ToastDialog(this);
    }
    if (m_toastdialog) {
        m_toastdialog->handleConnect();
    }
    return true;
}
#endif
void MainWindow::IsShowChooseKeyBtn(bool is)
{
    if (!is) {
        this->pushButtonChooseKeyNum->hide();
    } else {
        this->pushButtonChooseKeyNum->show();
    }
}

void MainWindow::dealOnConnect(std::string deviceName)
{
      qDebug() << "recv msg from EvtHandler";
      m_waitTimer->stop();
      #if !defined(IDEASHAREKEY)
           m_connectTimeoutTimer->stop();
      #endif
      this->labelWaitSign->setVisible(false);
      this->frameErrorInfo->setVisible(false);

      /* 清空投屏码 */
      on_pushButtonClear_clicked();
      /* 显示 分享界面 */
      #if defined(IDEASHAREKEY)
        m_toastdialog->handleConnectSuccess();
      #endif
        mDeviceName = QString(deviceName.c_str());
        showSendWindow();
        m_isSharing = false;
}

/* 处理底层抛上来的连接结果刷新UI */
void MainWindow::HandleConnectResult(std::string deviceName)
{

    ConnectResultEvent* connectResultEvent = new ConnectResultEvent(deviceName);
    QCoreApplication::postEvent(this,connectResultEvent);
}

void MainWindow::dealDisconnect()
{
    qDebug() << "disconnect ret.";
            //断连之后设备名称置空
    mDeviceName = "";
    showMainWindow();
    #if defined(IDEASHAREKEY)
    if (m_toastdialog != nullptr) {
        qDebug() << "show toast disconnect ...";
        m_toastdialog->handleDisConnectAndRetry();
     }
    #endif // IDEASHAREKEY
}

void MainWindow::HandleDisConnectResult()
{
    DisconnectResultEvent* disconnectResult = new DisconnectResultEvent();
    QCoreApplication::postEvent(this,disconnectResult);
}

void MainWindow::dealOnSharingDisplay()
{
    qDebug() << "Handler startSharing result";
    if (m_isSharing == false) {
          showStopWindow();
    #if defined(IDEASHAREKEY)
          m_toastdialog->showShareSuccess();
    #endif
    }
}
void MainWindow::HandleStartSharingResult()
{
    // 如果已经在共享中了，就丢弃这个消息，防止频繁切换页面导致的崩溃
    if (m_isSharing == true) {
      return;
    }
    ShareDisplayEvent* sharedisplay = new ShareDisplayEvent();
    QCoreApplication::postEvent(this,sharedisplay);

}


void MainWindow::HandleStopSharingResult()
{
    //如果没有在共享中，则丢弃这个消息
    if (m_isSharing == false) {
        return;
    }
    ShareStopEvent* shareStopEvent = new ShareStopEvent();
    QCoreApplication::postEvent(this,shareStopEvent);
}

void MainWindow::dealOnSharingStop()
{
    qDebug() << "Handler Stop Sharing result";
    if (m_isSharing == true) {
        showSendWindow();
    #if defined(IDEASHAREKEY)
        m_toastdialog->showShareStop();
    #endif
    }
}

void MainWindow::HandleGetRemoteSericeStatusResult(RemoteServiceStatus *remoteServiceStatus)
{
   qDebug() << "Handler get remote serivceStatusResult";
   if (remoteServiceStatus == NULL) {
     qDebug() << "remoteServiceStatus is null,so return";
     return;
   }
   mVolume = remoteServiceStatus->volume;
   int criterion = valueRangeConversion(horizontalSliderVolume->value(), 1);
   if (mVolume != criterion)
       this->horizontalSliderVolume->setValue(valueRangeConversion(mVolume, 0));
   // 扬声器打开
   if (remoteServiceStatus->isSpeakerMute == false) {
       showMuteVoiceWindow();
   } else {
       showUnMuteVoiceWindow();
   }
   //摄像头打开
   if (remoteServiceStatus->isCameraMute == false) {
       showVideoWindow();
   } else {
       showOpenVideoWindow();
   }
   // 麦有声
   if (remoteServiceStatus->isMute == false) {
       showMuteWindow();
   } else {
       showUnMuteWindow();
   }

   setRemoteControlBaseVersion(remoteServiceStatus->isBase);

   qDebug() << "set confstatus :" << mConfSate;
   //缺少会议状态的事件
   mIsChairMan = remoteServiceStatus->isChairman;
   this->pushButtonLeaveTheMeeting->setVisible(mConfSate == CONF_BUSY? true : false);
   showRemoteControlWindow();
}

void MainWindow::HandleUpdateMicMuteNotify(bool isMute)
{
    if (isMute == true) {
        // 麦无声，带斜杠， 按键作用是取消静音
       qDebug() << "mute the mic" <<endl;
       showUnMuteWindow();
    } else {
        // 麦有声，显示不带斜杠的图片， 正常图标，按键作用是静音
       qDebug() << "umute the mic" <<endl;
       showMuteWindow();
    }
}

void MainWindow::HandleUpdateSpeakerMuteNotify(bool isSpeakerMute)
{
    //扬声器无声
    if (isSpeakerMute == true) {
        //显示带斜杠的图片，按键作用是打开扬声器
         showUnMuteVoiceWindow();
    } else {
        //扬声器有声，显示不带斜杠的正常图片，按键作用是关闭扬声器
         showMuteVoiceWindow();
    }
}

void MainWindow::HandleUpdateCameraMuteNotfiy(bool isCameratMute)
{
     qDebug() << "Handler update camera mute notify";
    //摄像头关闭
    if (isCameratMute == true) {
        //显示带斜杠的图片，斜杠图片，按钮作用是打开摄像头
       showOpenVideoWindow();
    } else {
       //摄像头打开，显示不带斜杠的图片，正常图片，按键作用是关闭摄像头
       showVideoWindow();
    }
}

void MainWindow::HandleUpdateSpeakerVolumeNotify(int volume)
{
   VolumeUpdateEvent* volumeUpdateEvent = new VolumeUpdateEvent(volume);
   QCoreApplication::postEvent(this,volumeUpdateEvent);
}

void MainWindow::HandleUpdateChairManNotify(bool isChairMan)
{
    qDebug() << "handle update chairman notify isChairMan";
    mIsChairMan = isChairMan;

}

void MainWindow::HandleDevConfStatusNotify(ConfSate confState, AuxState auxState)
{
   qDebug() << "handle dev conf status notify";

   mConfSate = confState;
   if (mConfSate == CONF_IDLE){
     qDebug() << "Set chair man false";
     mIsChairMan = false;
   }
//   if (mConfSate != confState) {
//       mConfSate = confState;
//   } else {
//       //状态未发生变化
//       return;
//   }

   //刷新"离开按钮显示状态"
   this->pushButtonLeaveTheMeeting->setVisible(mConfSate == CONF_BUSY? true : false);
}

void MainWindow::dealServerStopShare()
{
    if (m_isSharing == true) {
        showSendWindow();
#if defined(IDEASHAREKEY)
        m_toastdialog->showShareStop();
#endif
    }
}
//服务端停发辅流
void  MainWindow::HandleServerStopShare(ShareAppErr reason)
{
    // 已经处于停止共享状态则不做任何UI切换，防止频繁的UI切换引起的多线程问题
    if (m_isSharing == false) {
      return;
    }
    ServerStopShareEvent* serverStopShareEvent = new ServerStopShareEvent();
    QCoreApplication::postEvent(this,serverStopShareEvent);
}

void MainWindow::dealServerDisconnect()
{
    qDebug() << "disconnect form server";
    showMainWindow();
}

// 服务端主动断开连接
void MainWindow::HandleServerDisconnect(ShareAppErr reason)
{
    ServerDisConnectEvent* serverDisconnectShareEvent = new ServerDisConnectEvent();
    QCoreApplication::postEvent(this,serverDisconnectShareEvent);
}
void MainWindow::HandleError(ShareAppErr errorCode)
{
        ErrorEvent* errorEvent = new ErrorEvent((int)errorCode);
        QCoreApplication::postEvent(this, errorEvent);

}

bool MainWindow::event(QEvent *event)
{
   if (event->type() == ErrorEvent::eventType()) {
      ErrorEvent* errorEvent = dynamic_cast<ErrorEvent*>(event);
      if (errorEvent == NULL) {
          qDebug() << "error event is null"<<endl;
         return false;
      }
      qDebug() << errorEvent->getErrorCode();
      ShareAppErr flag = (ShareAppErr)(errorEvent->getErrorCode());
      dealError(flag);
      return true;
   }
   if (event->type() == VolumeUpdateEvent::eventType()) {
      VolumeUpdateEvent* updateEvent =  dynamic_cast<VolumeUpdateEvent*>(event);
       if (updateEvent == NULL) {
           qDebug() << "update event is null"<<endl;
          return false;
       }
       qDebug() << updateEvent->getVolume();
       dealUpdateSliderVolume(updateEvent->getVolume());
       return true;
   }
   if (event->type() == ShareDisplayEvent::eventType()) {
//      ShareDisplayEvent* shareDisplayEvent = dynamic_cast<ShareDisplayEvent*>(event);
//      if (shareDisplayEvent == NULL) {
//          qDebug() << "share event is null"<<endl;
//         return false;

//      }
      qDebug() << "share display Event";
      dealOnSharingDisplay();
      return true;
   }
   if (event->type() == ShareStopEvent::eventType()){
//       ShareStopEvent* shareStopEvent = dynamic_cast<ShareStopEvent*>(event);
//       if (shareStopEvent == NULL) {
//           qDebug() << "share stop event is null"<<endl;
//          return false;
//       }
       qDebug() << "share stop display Event";
       dealOnSharingStop();
       return true;
   }
   if (event->type() == ConnectResultEvent::eventType()) {
       ConnectResultEvent* connectResultEvent = dynamic_cast<ConnectResultEvent*>(event);
       if (connectResultEvent == NULL) {
           qDebug() << "connect event is null"<<endl;
          return false;

       }
       qDebug() << "connect Event";
       dealOnConnect(connectResultEvent->getDeviceName());
       return true;
   }

   if (event->type() == DisconnectResultEvent::eventType()) {
//       DisconnectResultEvent* disconnectEvent = dynamic_cast<DisconnectResultEvent*>(event);
//       if (disconnectEvent == NULL) {
//           qDebug() << "disconnect event is null"<<endl;
//          return false;
//       }
       qDebug() << "disconnect Event";
       dealDisconnect();
       return true;
   }

   if (event->type() == ServerStopShareEvent::eventType()) {
       qDebug() << "server Stop share";
       dealServerStopShare();
       return true;
   }

   if (event->type() == ServerDisConnectEvent::eventType()) {
       qDebug() << "server disconnet";
       dealServerDisconnect();
       return true;
   }
   return QWidget::event(event);
}


void MainWindow::dealError(ShareAppErr errorCode)
{
       m_waitTimer->stop();
       #if !defined(IDEASHAREKEY)
       m_connectTimeoutTimer->stop();
       #endif
       //隐藏转圈
       this->labelWaitSign->setVisible(false);
       qDebug() << "recevice errcode" << errorCode;
        /* 显示 错误码*/
       this->frameErrorInfo->setVisible(true);
       this->labelResultInfo->setText(strerrno(errorCode));
       this->m_errorTimer->start();
}

void MainWindow::dealUpdateSliderVolume(int volume)
{
        qDebug() << "Handler speaker volume";
        mVolume = volume;
        qDebug() << "begin get the crition";
        int criterion = valueRangeConversion(horizontalSliderVolume->value(), 1);
        qDebug() << "end get the crition";
        if (mVolume != criterion)
        {
            qDebug() << "set the value";
            this->horizontalSliderVolume->setValue(valueRangeConversion(mVolume, 0));
            qDebug() << "end the value";
        }
}

void MainWindow::HandleEndConference()
{
   //清空会议主席状态，会议状态
   qDebug() << "Handler end conference";
   mIsChairMan = false;
   mConfSate = CONF_IDLE;
}

void MainWindow::HandleLeaveConference()
{
   //清空会议主席状态，会议状态
   qDebug() << "Handler leave conference";
   mIsChairMan = false;
   //离开会议主席状态需保留
   mConfSate = CONF_IDLE;
}

